export const generateScoreItemArr = function (score, showHalf) {
    let result = [];
    let tens = Math.floor(score / 10);

    if (tens > 0) {
        for (let i = 0; i <= tens && i < 10; i++) {
            result.unshift(i);
        }

        // Add blank string if tens > 0
        if (tens > 0) {
            result.unshift(0, '');
        }

        // Add numbers 1 to 9
        for (let i = 1; i <= 9; i++) {
            result.unshift(i);
        }
    } else {
        for (let i = 0; i <= score; i++) {
            result.unshift(i);
        }
    }

    // Add initial numbers based on the number of tens


    // Add half score if showHalf is true
    if (showHalf) {
        result.unshift('5', '.');
    }

    let itemHtml = ''
    const length = result.length
    for (let index = 0; index < length; index++) {
        const element = result[index] !== undefined ? result[index] : '';
        itemHtml += `<span class="item" style="width:27.97px;height:18.66px"><span>${element}</span></span>`
    }

    return itemHtml
}

/**
* 参数处理
* @param {*} params  参数
*/
export function tansParams (params) {
    let result = ''
    for (const propName of Object.keys(params)) {
        const value = params[propName];
        var part = encodeURIComponent(propName) + "=";
        if (value !== null && value !== "" && typeof (value) !== "undefined") {
            if (typeof value === 'object') {
                for (const key of Object.keys(value)) {
                    if (value[key] !== null && value[key] !== "" && typeof (value[key]) !== 'undefined') {
                        let params = propName + '[' + key + ']';
                        var subPart = encodeURIComponent(params) + "=";
                        result += subPart + encodeURIComponent(value[key]) + "&";
                    }
                }
            } else {
                result += part + encodeURIComponent(value) + "&";
            }
        }
    }
    return result
}
